package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.domain.TbClue;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessMapper tbBusinessMapper;
    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    /**
     * 添加商机跟进记录
     * @param businessTrackVo
     */
    @Override
    public void add(BusinessTrackVo businessTrackVo) {
        TbBusiness tbBusiness = new TbBusiness();
        BeanUtils.copyProperties(businessTrackVo,tbBusiness); //调用工具类copy
        tbBusiness.setId(businessTrackVo.getBusinessId());//设置商机id
        tbBusiness.setStatus(TbClue.StatusType.TOBUSINESS.getValue()); //设置状态为商机
        tbBusinessMapper.updateTbBusiness(tbBusiness);//调用修改方法

        TbBusinessTrackRecord tbBusinessTrackRecord = new TbBusinessTrackRecord();
        BeanUtils.copyProperties(businessTrackVo,tbBusinessTrackRecord);//调用工具类copy
        tbBusinessTrackRecord.setCreateBy(SecurityUtils.getUsername());//设置创建人
        tbBusinessTrackRecord.setCreateTime(new Date());//设置创建时间
        tbBusinessTrackRecord.setBusinessId(businessTrackVo.getBusinessId());//设置商机id
        tbBusinessTrackRecordMapper.add(tbBusinessTrackRecord); //调用添加方法
    }

    /**
     * 查询商机跟进记录
     * @param id
     * @return
     */
    @Override
    public List<TbBusinessTrackRecord> select(Long id) {
        return tbBusinessTrackRecordMapper.select(id);
    }
}
